﻿#include "FITKCustomDataXMLWriter.h"
#include <QFile>
#include <QDomDocument>
#include <QDomElement>
#include <QTextStream>

#include "FITK_Kernel/FITKAppFramework/FITKMessage.h"
#include "FITK_Interface/FITKInterfaceCustomData/FITKCDInterface.h"
#include "FITK_Interface/FITKInterfaceCustomData/FITKCDDataSolid.h"
#include "FITK_Interface/FITKInterfaceCustomData/FITKCDDataFluid.h"
#include "FITK_Interface/FITKInterfaceCustomData/FITKCDDataInlet.h"
#include "FITK_Interface/FITKInterfaceCustomData/FITKCDDataOutlet.h"
#include "FITK_Interface/FITKInterfaceCustomData/FITKCDMonitorSamplingPoint.h"
#include "FITK_Interface/FITKInterfaceCustomData/FITKCDCfgPSetPhysical.h"
#include "FITK_Interface/FITKInterfaceCustomData/FITKCDCfgPSetSwitch.h"
#include "FITK_Interface/FITKInterfaceCustomData/FITKCDCfgCSetComputation.h"
#include "FITK_Interface/FITKInterfaceCustomData/FITKCDCfgCSetBase.h"
#include "FITK_Interface/FITKInterfaceCustomData/FITKCDCfgCSetPath.h"
#include "FITK_Interface/FITKInterfaceCustomData/FITKCDPostprocess3DFixedWall.h"
#include "FITK_Interface/FITKInterfaceCustomData/FITKCDPostprocess3DRigidBody.h"
#include "FITK_Interface/FITKInterfaceCustomData/FITKCDPostprocess3DFLuid.h"


using namespace Interface;

QString INT2STR(int n)
{
	return QString::number(n);
}

QString DBL2STR(double d)
{
	return QString::number(d, 'f');
}

QString VEC2STR(double* d)
{
	return DBL2STR(d[0]) + "," + DBL2STR(d[1]) + "," + DBL2STR(d[2]);
}

QString BOOL2STR(bool b)
{
	return b ? "true" : "false";
}

void FITKCustomDataXMLWriter::consoleMessage(int level, const QString& str)
{
	//判断消息等级
	switch (level)
	{
	case 1:AppFrame::FITKMessageNormal(str); break;
	case 2: AppFrame::FITKMessageWarning(str); break;
	case 3:AppFrame::FITKMessageError(str); break;
	default: AppFrame::FITKMessageError(str); break;
	}
}

void FITKCustomDataXMLWriter::saveFile()
{
	if (!_file)
		return;

	QTextStream* stream = new QTextStream(_file);
	_document->save(*stream, 4);
	_file->close();
	delete stream;
}

void FITKCustomDataXMLWriter::run()
{
	writeVersion();
	writeRoot();
	writeData();
	writeMonitor();
	writeConfiguration();
	writePostprocess();

	consoleMessage(1, "Export Custom Data XML Succeed.");
}


void FITKCustomDataXMLWriter::writeVersion()
{
	QDomProcessingInstruction instruction = _document->createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
	_document->appendChild(instruction);
}

void FITKCustomDataXMLWriter::writeRoot()
{
	// root ele
	auto root = _document->createElement("Project");
	_document->appendChild(root);
}

void FITKCustomDataXMLWriter::writeData()
{
	auto root = _document->documentElement();

	auto dataEle = _document->createElement("Data");
	root.appendChild(dataEle);

	writeDataSolid(dataEle);
	writeDataFluid(dataEle);
	writeDataInlet(dataEle);
	writeDataOutlet(dataEle);
}

void FITKCustomDataXMLWriter::writeDataSolid(QDomElement ele)
{
	auto solidEle = _document->createElement("Solid");
	ele.appendChild(solidEle);

	auto pSolidManager = Interface::FITKCDInterface::getInstance()->getCDDataSolidManager();
	for (int i = 0; i < pSolidManager->getDataCount(); i++)
	{
		auto pData = pSolidManager->getDataByIndex(i);

		auto subSolidEle = _document->createElement("Solid_Data");
		subSolidEle.setAttribute("name", pData->getDataObjectName());
		solidEle.appendChild(subSolidEle);

		auto subEle1 = _document->createElement("Solid_Type");
		auto subEle2 = _document->createElement("Material");
		auto subEle3 = _document->createElement("Density");
		auto subEle4 = _document->createElement("Rigid_Type");
		auto subEle5 = _document->createElement("Mass");
		auto subEle6 = _document->createElement("Custom_Defined_Inertia_Matrix");
		auto subEle7 = _document->createElement("Centroid");
		auto subEle8 = _document->createElement("Inertia_Matrix_xx");
		auto subEle9 = _document->createElement("Inertia_Matrix_yy");
		auto subEle10 = _document->createElement("Inertia_Matrix_zz");
		auto subEle11 = _document->createElement("Inertia_Matrix_xy");
		auto subEle12 = _document->createElement("Inertia_Matrix_xz");
		auto subEle13 = _document->createElement("Inertia_Matrix_yz");
		auto subEle14 = _document->createElement("Linear_Velocity");
		auto subEle15 = _document->createElement("Angular_Velocity");
		auto subEle16 = _document->createElement("Initial_Euler_Angles");

		auto subEle17 = _document->createElement("Type_of_Element");
		auto subEle18 = _document->createElement("In_or_Out_Normalvector");
		auto subEle19 = _document->createElement("Specified_Axis");
		auto subEle20 = _document->createElement("Constrain_DOF");
		auto subEle21 = _document->createElement("Freeze_Movement_X");
		auto subEle22 = _document->createElement("Freeze_Movement_Y");
		auto subEle23 = _document->createElement("Freeze_Movement_Z");
		auto subEle24 = _document->createElement("Freeze_Rotation_X");
		auto subEle25 = _document->createElement("Freeze_Rotation_Y");
		auto subEle26 = _document->createElement("Freeze_Rotation_Z");

		subEle1.appendChild(_document->createTextNode(INT2STR(pData->getSolid_Type())));
		subEle2.appendChild(_document->createTextNode(INT2STR(pData->getMaterial())));
		subEle3.appendChild(_document->createTextNode(DBL2STR(pData->getDensity())));
		subEle4.appendChild(_document->createTextNode(INT2STR(pData->getRigid_Type())));
		subEle5.appendChild(_document->createTextNode(DBL2STR(pData->getMass())));
		subEle6.appendChild(_document->createTextNode(BOOL2STR(pData->getCustom_Defined_Inertia_Matrix())));
		subEle7.appendChild(_document->createTextNode(VEC2STR(pData->getCentroid())));
		subEle8.appendChild(_document->createTextNode(DBL2STR(pData->getInertia_Matrix_xx())));
		subEle9.appendChild(_document->createTextNode(DBL2STR(pData->getInertia_Matrix_yy())));
		subEle10.appendChild(_document->createTextNode(DBL2STR(pData->getInertia_Matrix_zz())));
		subEle11.appendChild(_document->createTextNode(DBL2STR(pData->getInertia_Matrix_xy())));
		subEle12.appendChild(_document->createTextNode(DBL2STR(pData->getInertia_Matrix_xz())));
		subEle13.appendChild(_document->createTextNode(DBL2STR(pData->getInertia_Matrix_yz())));
		subEle14.appendChild(_document->createTextNode(VEC2STR(pData->getLinear_Velocity())));
		subEle15.appendChild(_document->createTextNode(VEC2STR(pData->getAngular_Velocity())));
		subEle16.appendChild(_document->createTextNode(VEC2STR(pData->getInitial_Euler_Angles())));

		subEle17.appendChild(_document->createTextNode(INT2STR(pData->getType_of_Element())));
		subEle18.appendChild(_document->createTextNode(INT2STR(pData->getIn_or_Out_Normalvector())));
		subEle19.appendChild(_document->createTextNode(VEC2STR(pData->getSpecified_Axis())));
		subEle20.appendChild(_document->createTextNode(BOOL2STR(pData->getConstrain_DOF())));
		subEle21.appendChild(_document->createTextNode(BOOL2STR(pData->getFreeze_Movement_X())));
		subEle22.appendChild(_document->createTextNode(BOOL2STR(pData->getFreeze_Movement_Y())));
		subEle23.appendChild(_document->createTextNode(BOOL2STR(pData->getFreeze_Movement_Z())));
		subEle24.appendChild(_document->createTextNode(BOOL2STR(pData->getFreeze_Rotation_X())));
		subEle25.appendChild(_document->createTextNode(BOOL2STR(pData->getFreeze_Rotation_Y())));
		subEle26.appendChild(_document->createTextNode(BOOL2STR(pData->getFreeze_Rotation_Z())));

		subSolidEle.appendChild(subEle1);
		subSolidEle.appendChild(subEle2);
		subSolidEle.appendChild(subEle3);
		subSolidEle.appendChild(subEle4);
		subSolidEle.appendChild(subEle5);
		subSolidEle.appendChild(subEle6);
		subSolidEle.appendChild(subEle7);
		subSolidEle.appendChild(subEle8);
		subSolidEle.appendChild(subEle9);
		subSolidEle.appendChild(subEle10);
		subSolidEle.appendChild(subEle11);
		subSolidEle.appendChild(subEle12);
		subSolidEle.appendChild(subEle13);
		subSolidEle.appendChild(subEle14);
		subSolidEle.appendChild(subEle15);
		subSolidEle.appendChild(subEle16);

		subSolidEle.appendChild(subEle17);
		subSolidEle.appendChild(subEle18);
		subSolidEle.appendChild(subEle19);
		subSolidEle.appendChild(subEle20);
		subSolidEle.appendChild(subEle21);
		subSolidEle.appendChild(subEle22);
		subSolidEle.appendChild(subEle23);
		subSolidEle.appendChild(subEle24);
		subSolidEle.appendChild(subEle25);
		subSolidEle.appendChild(subEle26);
	}
}

void FITKCustomDataXMLWriter::writeDataFluid(QDomElement ele)
{
	auto fluidEle = _document->createElement("Fluid");
	ele.appendChild(fluidEle);

	auto pFluidManager = Interface::FITKCDInterface::getInstance()->getCDDataFluidManager();
	for (int i = 0; i < pFluidManager->getDataCount(); i++)
	{
		auto pData = pFluidManager->getDataByIndex(i);

		auto subFluidEle = _document->createElement("Fluid_Data");
		subFluidEle.setAttribute("name", pData->getDataObjectName());
		fluidEle.appendChild(subFluidEle);

		auto subEle1 = _document->createElement("Material");
		auto subEle2 = _document->createElement("Initialize_Hydrostatic_Pressure");
		auto subEle3 = _document->createElement("Free_Surface");
		auto subEle4 = _document->createElement("Dynamic_Viscosity");
		auto subEle5 = _document->createElement("Kinematic_Viscosity");
		auto subEle6 = _document->createElement("Artificial_Viscosity");

		subEle1.appendChild(_document->createTextNode(INT2STR(pData->getMaterial())));
		subEle2.appendChild(_document->createTextNode(BOOL2STR(pData->getInitialize_Hydrostatic_Pressure())));
		subEle3.appendChild(_document->createTextNode(VEC2STR(pData->getFree_Surface())));
		subEle4.appendChild(_document->createTextNode(DBL2STR(pData->getDynamic_Viscosity())));
		subEle5.appendChild(_document->createTextNode(DBL2STR(pData->getKinematic_Viscosity())));
		subEle6.appendChild(_document->createTextNode(DBL2STR(pData->getArtificial_Viscosity())));

		subFluidEle.appendChild(subEle1);
		subFluidEle.appendChild(subEle2);
		subFluidEle.appendChild(subEle3);
		subFluidEle.appendChild(subEle4);
		subFluidEle.appendChild(subEle5);
		subFluidEle.appendChild(subEle6);
	}
}

void FITKCustomDataXMLWriter::writeDataInlet(QDomElement ele)
{
	auto inletEle = _document->createElement("Inlet");
	ele.appendChild(inletEle);

	auto pInletManager = Interface::FITKCDInterface::getInstance()->getCDDataInletManager();
	for (int i = 0; i < pInletManager->getDataCount(); i++)
	{
		auto pData = pInletManager->getDataByIndex(i);

		auto subInletEle = _document->createElement("Inlet_Data");
		subInletEle.setAttribute("name", pData->getDataObjectName());
		inletEle.appendChild(subInletEle);

		auto subEle1 = _document->createElement("Inlet_Shape");
		auto subEle2 = _document->createElement("Position");
		auto subEle3 = _document->createElement("Flow_Rate");
		auto subEle4 = _document->createElement("Inlet_Area");

		subEle1.appendChild(_document->createTextNode(INT2STR(pData->getInlet_Shape())));
		subEle2.appendChild(_document->createTextNode(VEC2STR(pData->getPosition())));
		subEle3.appendChild(_document->createTextNode(VEC2STR(pData->getFlow_Rate())));
		subEle4.appendChild(_document->createTextNode(DBL2STR(pData->getInlet_Area())));

		subInletEle.appendChild(subEle1);
		subInletEle.appendChild(subEle2);
		subInletEle.appendChild(subEle3);
		subInletEle.appendChild(subEle4);
	}
}

void FITKCustomDataXMLWriter::writeDataOutlet(QDomElement ele)
{
	auto outletEle = _document->createElement("Outlet");
	ele.appendChild(outletEle);

	auto pOutletManager = Interface::FITKCDInterface::getInstance()->getCDDataOutletManager();
	for (int i = 0; i < pOutletManager->getDataCount(); i++)
	{
		auto pData = pOutletManager->getDataByIndex(i);

		auto subOutletEle = _document->createElement("Outlet_Data");
		subOutletEle.setAttribute("name", pData->getDataObjectName());
		outletEle.appendChild(subOutletEle);

		auto subEle1 = _document->createElement("Minimum_xyz");
		auto subEle2 = _document->createElement("Maximum_xyz");

		subEle1.appendChild(_document->createTextNode(VEC2STR(pData->getMinimum_xyz())));
		subEle2.appendChild(_document->createTextNode(VEC2STR(pData->getMaximum_xyz())));

		subOutletEle.appendChild(subEle1);
		subOutletEle.appendChild(subEle2);
	}
}

void FITKCustomDataXMLWriter::writeMonitor()
{
	auto root = _document->documentElement();

	auto monEle = _document->createElement("Monitor");
	root.appendChild(monEle);

	writeMonitorSamplingPoint(monEle);
}

void FITKCustomDataXMLWriter::writeMonitorSamplingPoint(QDomElement ele)
{
	auto spEle = _document->createElement("Sampling_Point");
	ele.appendChild(spEle);

	auto pSPManager = Interface::FITKCDInterface::getInstance()->getCDSamplingPointManager();
	for (int i = 0; i < pSPManager->getDataCount(); i++)
	{
		auto pData = pSPManager->getDataByIndex(i);

		auto pntEle = _document->createElement("Position");
		pntEle.setAttribute("name", pData->getDataObjectName());
		pntEle.appendChild(_document->createTextNode(VEC2STR(pData->getPosition())));
		spEle.appendChild(pntEle);
	}
}

void FITKCustomDataXMLWriter::writeConfiguration()
{
	auto root = _document->documentElement();

	auto cfgEle = _document->createElement("Configuration");
	root.appendChild(cfgEle);

	writeCfgPSet(cfgEle);
	writeCfgCSet(cfgEle);
}

void FITKCustomDataXMLWriter::writeCfgPSet(QDomElement ele)
{
	auto pSetEle = _document->createElement("Physical_Parameter_Settings");
	ele.appendChild(pSetEle);

	auto pPhysicalManager = Interface::FITKCDInterface::getInstance()->getCDCfgPhysicalManager();
	for (int i = 0; i < pPhysicalManager->getDataCount(); i++)
	{
		auto pData = pPhysicalManager->getDataByIndex(i);

		auto physicalEle = _document->createElement("Physical");
		pSetEle.appendChild(physicalEle);

		auto subEle1 = _document->createElement("Gravity");
		auto subEle2 = _document->createElement("SpsSmag");
		auto subEle3 = _document->createElement("SpsBlin");
		auto subEle4 = _document->createElement("Alpavisc");
		auto subEle5 = _document->createElement("Realvisc");

		subEle1.appendChild(_document->createTextNode(VEC2STR(pData->getGravity())));
		subEle2.appendChild(_document->createTextNode(DBL2STR(pData->getSpsSmag())));
		subEle3.appendChild(_document->createTextNode(DBL2STR(pData->getSpsBlin())));
		subEle4.appendChild(_document->createTextNode(DBL2STR(pData->getAlpavisc())));
		subEle5.appendChild(_document->createTextNode(BOOL2STR(pData->getRealvisc())));

		physicalEle.appendChild(subEle1);
		physicalEle.appendChild(subEle2);
		physicalEle.appendChild(subEle3);
		physicalEle.appendChild(subEle4);
		physicalEle.appendChild(subEle5);
	}

	auto pSwitchManager = Interface::FITKCDInterface::getInstance()->getCDCfgSwitchManager();
	for (int i = 0; i < pSwitchManager->getDataCount(); i++)
	{
		auto pData = pSwitchManager->getDataByIndex(i);

		auto switchEle = _document->createElement("Switch");
		pSetEle.appendChild(switchEle);

		auto subEle1 = _document->createElement("Pressure_Threshold");
		auto subEle2 = _document->createElement("Minimum_Pressure");
		auto subEle3 = _document->createElement("Density_Reinitial");
		auto subEle4 = _document->createElement("Reinitial_Steps");
		auto subEle5 = _document->createElement("Tic");
		auto subEle6 = _document->createElement("Resort_Fluid");
		auto subEle7 = _document->createElement("Slip");
		auto subEle8 = _document->createElement("LJ_Force");
		auto subEle9 = _document->createElement("LJ_Param");
		auto subEle10 = _document->createElement("PST");

		subEle1.appendChild(_document->createTextNode(BOOL2STR(pData->getPressure_Threshold())));
		subEle2.appendChild(_document->createTextNode(DBL2STR(pData->getMinimum_Pressure())));
		subEle3.appendChild(_document->createTextNode(BOOL2STR(pData->getDensity_Reinitial())));
		subEle4.appendChild(_document->createTextNode(INT2STR(pData->getReinitial_Steps())));
		subEle5.appendChild(_document->createTextNode(BOOL2STR(pData->getTic())));
		subEle6.appendChild(_document->createTextNode(BOOL2STR(pData->getResort_Fluid())));
		subEle7.appendChild(_document->createTextNode(BOOL2STR(pData->getSlip())));
		subEle8.appendChild(_document->createTextNode(BOOL2STR(pData->getLJ_Force())));
		subEle9.appendChild(_document->createTextNode(DBL2STR(pData->getLJ_Param())));
		subEle10.appendChild(_document->createTextNode(BOOL2STR(pData->getPST())));

		switchEle.appendChild(subEle1);
		switchEle.appendChild(subEle2);
		switchEle.appendChild(subEle3);
		switchEle.appendChild(subEle4);
		switchEle.appendChild(subEle5);
		switchEle.appendChild(subEle6);
		switchEle.appendChild(subEle7);
		switchEle.appendChild(subEle8);
		switchEle.appendChild(subEle9);
		switchEle.appendChild(subEle10);
	}
}

void FITKCustomDataXMLWriter::writeCfgCSet(QDomElement ele)
{
	auto cSetEle = _document->createElement("Computation_Setting");
	ele.appendChild(cSetEle);

	auto pComputationManager = Interface::FITKCDInterface::getInstance()->getCDCfgComputationManager();
	for (int i = 0; i < pComputationManager->getDataCount(); i++)
	{
		auto pData = pComputationManager->getDataByIndex(i);

		auto computationEle = _document->createElement("Computation_Domain");
		cSetEle.appendChild(computationEle);

		auto subEle1 = _document->createElement("Minimum_xyz");
		auto subEle2 = _document->createElement("Maximum_xyz");

		subEle1.appendChild(_document->createTextNode(VEC2STR(pData->getMinimum_xyz())));
		subEle2.appendChild(_document->createTextNode(VEC2STR(pData->getMaximum_xyz())));

		computationEle.appendChild(subEle1);
		computationEle.appendChild(subEle2);
	}

	auto pBaseManager = Interface::FITKCDInterface::getInstance()->getCDCfgBaseManager();
	for (int i = 0; i < pBaseManager->getDataCount(); i++)
	{
		auto pData = pBaseManager->getDataByIndex(i);

		auto baseEle = _document->createElement("Base");
		cSetEle.appendChild(baseEle);

		auto subEle1 = _document->createElement("Sound_Speed");
		auto subEle2 = _document->createElement("CFL");
		auto subEle3 = _document->createElement("Background_Pressure");
		auto subEle4 = _document->createElement("Initial_dx");
		auto subEle5 = _document->createElement("Simulation_Time");
		auto subEle6 = _document->createElement("Save_Time_Steps");
		auto subEle7 = _document->createElement("Monitor_Time_Steps");
		auto subEle8 = _document->createElement("Print_Steps");
		auto subEle9 = _document->createElement("Maximum_Particles");
		auto subEle10 = _document->createElement("Smoothed_Kernel_Function");
		auto subEle11 = _document->createElement("Time_Integration");
		auto subEle12 = _document->createElement("Output_File_Type");
		auto subEle13 = _document->createElement("Bound_Output");
		auto subEle14 = _document->createElement("Compute_Force");
		auto subEle15 = _document->createElement("Compute_Rigid_Normalvector");
		auto subEle16 = _document->createElement("Delete_Particles");
		auto subEle17 = _document->createElement("Rigid_Output");

		subEle1.appendChild(_document->createTextNode(DBL2STR(pData->getSound_Speed())));
		subEle2.appendChild(_document->createTextNode(DBL2STR(pData->getCFL())));
		subEle3.appendChild(_document->createTextNode(DBL2STR(pData->getBackground_Pressure())));
		subEle4.appendChild(_document->createTextNode(DBL2STR(pData->getInitial_dx())));
		subEle5.appendChild(_document->createTextNode(DBL2STR(pData->getSimulation_Time())));
		subEle6.appendChild(_document->createTextNode(DBL2STR(pData->getSave_Time_Steps())));
		subEle7.appendChild(_document->createTextNode(DBL2STR(pData->getMonitor_Time_Steps())));
		subEle8.appendChild(_document->createTextNode(INT2STR(pData->getPrint_Steps())));
		subEle9.appendChild(_document->createTextNode(INT2STR(pData->getMaximum_Particles())));
		subEle10.appendChild(_document->createTextNode(INT2STR(pData->getSmoothed_Kernel_Function())));
		subEle11.appendChild(_document->createTextNode(INT2STR(pData->getTime_Integration())));
		subEle12.appendChild(_document->createTextNode(INT2STR(pData->getOutput_File_Type())));
		subEle13.appendChild(_document->createTextNode(BOOL2STR(pData->getBound_Output())));
		subEle14.appendChild(_document->createTextNode(INT2STR(pData->getCompute_Force())));
		subEle15.appendChild(_document->createTextNode(BOOL2STR(pData->getCompute_Rigid_Normalvector())));
		subEle16.appendChild(_document->createTextNode(BOOL2STR(pData->getDelete_Particles())));
		subEle17.appendChild(_document->createTextNode(BOOL2STR(pData->getRigid_Output())));

		baseEle.appendChild(subEle1);
		baseEle.appendChild(subEle2);
		baseEle.appendChild(subEle3);
		baseEle.appendChild(subEle4);
		baseEle.appendChild(subEle5);
		baseEle.appendChild(subEle6);
		baseEle.appendChild(subEle7);
		baseEle.appendChild(subEle8);
		baseEle.appendChild(subEle9);
		baseEle.appendChild(subEle10);
		baseEle.appendChild(subEle11);
		baseEle.appendChild(subEle12);
		baseEle.appendChild(subEle13);
		baseEle.appendChild(subEle14);
		baseEle.appendChild(subEle15);
		baseEle.appendChild(subEle16);
		baseEle.appendChild(subEle17);
	}

	auto pPathManager = Interface::FITKCDInterface::getInstance()->getCDCfgPathManager();
	for (int i = 0; i < pPathManager->getDataCount(); i++)
	{
		auto pData = pPathManager->getDataByIndex(i);

		auto pathEle = _document->createElement("Path_Definition");
		cSetEle.appendChild(pathEle);

		auto subEle1 = _document->createElement("Data_Storage_Path");
		auto subEle2 = _document->createElement("Data_Reading_Path");
		auto subEle3 = _document->createElement("Name_Of_STL");

		subEle1.appendChild(_document->createTextNode(pData->getData_Storage_Path()));
		subEle2.appendChild(_document->createTextNode(pData->getData_Reading_Path()));
		subEle3.appendChild(_document->createTextNode(pData->getName_Of_STL()));

		pathEle.appendChild(subEle1);
		pathEle.appendChild(subEle2);
		pathEle.appendChild(subEle3);
	}
}

void FITKCustomDataXMLWriter::writePostprocess()
{
	auto root = _document->documentElement();

	auto postEle = _document->createElement("Postprocess");
	root.appendChild(postEle);

	writePost3DVisualization(postEle);
}

void FITKCustomDataXMLWriter::writePost3DVisualization(QDomElement ele)
{
	auto post3dEle = _document->createElement("3D_Visualization");
	ele.appendChild(post3dEle);

	auto pFWManager = Interface::FITKCDInterface::getInstance()->getCDPost3DFixedWallManager();
	for (int i = 0; i < pFWManager->getDataCount(); i++)
	{
		auto pData = pFWManager->getDataByIndex(i);

		auto fwEle = _document->createElement("Fixed_Wall");
		post3dEle.appendChild(fwEle);

		auto subEle1 = _document->createElement("Coloring");
		auto subEle2 = _document->createElement("Single_Color");
		auto subEle3 = _document->createElement("Visible");
		auto subEle4 = _document->createElement("Opicity");
		auto subEle5 = _document->createElement("Display_Mode");

		subEle1.appendChild(_document->createTextNode(INT2STR(pData->getColoring())));
		subEle2.appendChild(_document->createTextNode(pData->getSingle_Color().name()));
		subEle3.appendChild(_document->createTextNode(BOOL2STR(pData->getVisible())));
		subEle4.appendChild(_document->createTextNode(DBL2STR(pData->getOpicity())));
		subEle5.appendChild(_document->createTextNode(INT2STR(pData->getDisplay_Mode())));

		fwEle.appendChild(subEle1);
		fwEle.appendChild(subEle2);
		fwEle.appendChild(subEle3);
		fwEle.appendChild(subEle4);
		fwEle.appendChild(subEle5);
	}

	auto pRBManager = Interface::FITKCDInterface::getInstance()->getCDPost3DRigidBodyManager();
	for (int i = 0; i < pRBManager->getDataCount(); i++)
	{
		auto pData = pRBManager->getDataByIndex(i);

		auto rbEle = _document->createElement("Rigid_Body");
		post3dEle.appendChild(rbEle);

		auto subEle1 = _document->createElement("Coloring");
		auto subEle2 = _document->createElement("Single_Color");
		auto subEle3 = _document->createElement("Visible");
		auto subEle4 = _document->createElement("Opicity");
		auto subEle5 = _document->createElement("Display_Mode");

		subEle1.appendChild(_document->createTextNode(INT2STR(pData->getColoring())));
		subEle2.appendChild(_document->createTextNode(pData->getSingle_Color().name()));
		subEle3.appendChild(_document->createTextNode(BOOL2STR(pData->getVisible())));
		subEle4.appendChild(_document->createTextNode(DBL2STR(pData->getOpicity())));
		subEle5.appendChild(_document->createTextNode(INT2STR(pData->getDisplay_Mode())));

		rbEle.appendChild(subEle1);
		rbEle.appendChild(subEle2);
		rbEle.appendChild(subEle3);
		rbEle.appendChild(subEle4);
		rbEle.appendChild(subEle5);
	}

	auto pFLManager = Interface::FITKCDInterface::getInstance()->getCDPost3DFLuidManager();
	for (int i = 0; i < pFLManager->getDataCount(); i++)
	{
		auto pData = pFLManager->getDataByIndex(i);

		auto flEle = _document->createElement("FLuid");
		post3dEle.appendChild(flEle);

		auto subEle1 = _document->createElement("Coloring");
		auto subEle2 = _document->createElement("Single_Color");
		auto subEle3 = _document->createElement("Visible");
		auto subEle4 = _document->createElement("Opicity");
		auto subEle5 = _document->createElement("Display_Mode");

		subEle1.appendChild(_document->createTextNode(INT2STR(pData->getColoring())));
		subEle2.appendChild(_document->createTextNode(pData->getSingle_Color().name()));
		subEle3.appendChild(_document->createTextNode(BOOL2STR(pData->getVisible())));
		subEle4.appendChild(_document->createTextNode(DBL2STR(pData->getOpicity())));
		subEle5.appendChild(_document->createTextNode(INT2STR(pData->getDisplay_Mode())));

		flEle.appendChild(subEle1);
		flEle.appendChild(subEle2);
		flEle.appendChild(subEle3);
		flEle.appendChild(subEle4);
		flEle.appendChild(subEle5);
	}
}